package com.usian.service.impl;

import com.usian.pojo.TbItem;
import com.usian.redis.RedisClient;
import com.usian.service.CartService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 购物车操作业务层
 */
@Service
public class CartServiceImpl implements CartService {
    @Value("${CART_REDIS_NAME}")
    private String CART_REDIS_NAME;
    @Resource
    private RedisClient redisClient;
    //根据用户 ID 查询用户购物车
    @Override
    public Map<String, TbItem> selectCartByUserId(String userId) {
        return (Map<String, TbItem>) redisClient.hget(CART_REDIS_NAME,userId);
    }
    //添加购物车
    @Override
    public Boolean insertCart(String userId, Map<String, TbItem> map) {
        return redisClient.hset(CART_REDIS_NAME, userId, map);
    }
}
